Skip to content

[fix] Make ID the source of truth for vpc and subnet names#807

Merged
komer3 merged 2 commits intolinode:mainfrom
cbbond:dont-filter-by-vpc-label
Jul 23, 2025
Merged

[fix] Make ID the source of truth for vpc and subnet names#807
komer3 merged 2 commits intolinode:mainfrom
cbbond:dont-filter-by-vpc-label

Conversation

@cbbond
Copy link
Contributor

@cbbond cbbond commented Jul 21, 2025

What this PR does / why we need it:

We currently filter the Linode API's ListVPCs response by both VPC ID and label when deciding whether to create a new VPC or update an existing one. This PR removes the latter filter and only checks for existing VPCs that match the ID found on the LinodeVPC resource. VPC ID is immutable and should be a sufficient filter for finding VPCs. Without this fix, any change to the VPC's label outside of CAPL will result in CAPL trying to create a new VPC when the underlying resource still exists.

Similarly, we currently build a map of subnets by label based on a list of VPC subnets we get from the Linode API. This method is vulnerable to the same issue in which any change to a subnet label after creation will prevent CAPL from reconciling the subnet further. This PR fixes this issue by building two maps that are keyed by both label and subnet ID. The code defaults to ID where possible but falls back to the label when the subnet ID is not yet populated (i.e. the first time we are reconciling a new subnet).

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged): N/A

Special notes for your reviewer:

  • Existing behavior is preserved for subnets, we either adopt an existing subnet or create a new one based on whether the subnet is in the API response map
  • The Linode API is the new source of truth for subnet labels, i.e. if a subnet label is updated via CloudManager then CAPL will adopt that label and update the LinodeVPC spec
  • Added a test case where both the VPC and subnet labels change

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

@cbbond cbbond force-pushed the dont-filter-by-vpc-label branch from da4d3b2 to 125dc8d Compare July 21, 2025 21:23
@cbbond cbbond temporarily deployed to prod-external July 21, 2025 21:23 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.25%. Comparing base (eb218ad) to head (ceb865d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #807      +/-   ##
==========================================
+ Coverage   63.16%   63.25%   +0.08%     
==========================================
  Files          71       71              
  Lines        7292     7304      +12     
==========================================
+ Hits         4606     4620      +14     
+ Misses       2415     2414       -1     
+ Partials      271      270       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cbbond cbbond temporarily deployed to prod-external July 22, 2025 13:26 — with GitHub Actions Inactive
@cbbond cbbond temporarily deployed to prod-external July 22, 2025 13:27 — with GitHub Actions Inactive
@cbbond cbbond changed the title [fix] Don't filter VPCs by label [fix] Make ID the source of truth for vpc and subnet names Jul 22, 2025
@komer3 komer3 requested a review from Copilot July 22, 2025 19:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where CAPL (Cluster API Provider Linode) fails to properly reconcile VPCs and subnets when their labels are changed outside of CAPL. The fix makes resource IDs the primary source of truth instead of relying on label matching.

Key changes:

  • Removes label-based filtering when looking up existing VPCs, using only VPC ID
  • Implements dual mapping for subnets (by both ID and label) to handle label changes gracefully
  • Updates subnet reconciliation logic to prefer ID-based lookups with label fallback

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/controller/linodevpc_controller_helpers.go Core logic changes to remove label filtering for VPCs and implement dual subnet mapping
internal/controller/linodevpc_controller_test.go New test case covering VPC and subnet label changes
Comments suppressed due to low confidence (2)

internal/controller/linodevpc_controller_helpers.go:88

  • [nitpick] The variable name 'subnetsByLabel' uses camelCase inconsistent with Go naming conventions. It should be 'subnetsByLabel' or consider 'subnetConfigByLabel' for clarity.
	subnetsByLabel := make(map[string]SubnetConfig, len(vpc.Subnets))

internal/controller/linodevpc_controller_helpers.go:89

  • The variable name 'subnetsById' should be 'subnetsByID' to follow Go naming conventions where 'ID' should be capitalized.
	subnetsById := make(map[int]SubnetConfig, len(vpc.Subnets))

Copy link
Contributor

@komer3 komer3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@komer3 komer3 merged commit f3b5e58 into linode:main Jul 23, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants